﻿Module App
    Public Str As String
    Public UserId As Int16
    Public UserName As String
    Public UserFullName As String
    Public AuthorizedPermissions As New DataTable

    Public Function IsAuthorized(ByVal permission As Permissions) As Boolean
        For Each row In AuthorizedPermissions.Rows
            If row(0) = permission Then
                Return True
            End If
        Next
        Return False
    End Function

End Module

'WITH TMP(LEVEL,PermissionId,PermissionName)
'As
'(
'  SELECT 1 AS LEVEL,
'         PermissionId,
'         CAST(PermissionName AS NVARCHAR(MAX)) AS PermissionName
'    FROM system.Permission e
'    WHERE  ParentId=0  
'  UNION ALL 
'  SELECT t.LEVEL+1,e.PermissionId,t.PermissionName+'_'+e.PermissionName
'  FROM system.Permission e
'    INNER JOIN TMP t ON e.ParentId=t.PermissionId
'  WHERE t.LEVEL<100 -- avoid infinite.
')
'SELECT PermissionName+'='+CONVERT(NVARCHAR,PermissionId)+','
'FROM TMP
'ORDER BY PermissionName;

Public Enum Permissions
    Manage = 2
    'Manage_Category = 5
    'Manage_Category_Add = 10
    'Manage_Category_Delete = 12
    'Manage_Category_Edit = 11
    'Manage_Category_View = 9

    Manage_Employee = 8
    Manage_Employee_Add = 10
    Manage_Employee_Delete = 12
    Manage_Employee_Edit = 11
    Manage_Employee_View = 9
    Manage_Employee_Detail = 13

    Manage_Education = 14
    Manage_Education_Add = 17
    Manage_Education_Delete = 19
    Manage_Education_Edit = 18
    Manage_Education_View = 16

    Manage_Experience = 21
    Manage_Experience_Add = 23
    Manage_Experience_Delete = 25
    Manage_Experience_Edit = 24
    Manage_Experience_View = 22

    Manage_Family = 26
    Manage_Family_Add = 28
    Manage_Family_Delete = 30
    Manage_Family_Edit = 29
    Manage_Family_View = 27

    Manage_Department = 31
    Manage_Department_Add = 33
    Manage_Department_Delete = 35
    Manage_Department_Edit = 34
    Manage_Department_View = 32

    Manage_permission = 36
    Manage_permission_Add = 38
    Manage_permission_Delete = 40
    Manage_permission_Edit = 39
    Manage_permission_View = 37

    Manage_LeaveTime = 41
    Manage_LeaveTime_Add = 43
    Manage_LeaveTime_Delete = 45
    Manage_LeaveTime_Edit = 44
    Manage_LeaveTime_View = 42

    Manage_Resign = 46
    Manage_Resign_Add = 48
    Manage_Resign_Delete = 50
    Manage_Resign_Edit = 49
    Manage_Resign_View = 47

    Manage_Accident = 51
    Manage_Accident_Add = 53
    Manage_Accident_Delete = 55
    Manage_Accident_Edit = 54
    Manage_Accident_View = 52

    Manage_Insurance = 61
    Manage_Insurance_Add = 63
    Manage_Insurance_Delete = 65
    Manage_Insurance_Edit = 64
    Manage_Insurance_View = 62

    Manage_Warning = 66
    Manage_Warning_Add = 68
    Manage_Warning_Delete = 70
    Manage_Warning_Edit = 69
    Manage_Warning_View = 67

    Manage_WorkPerformance = 71
    Manage_WorkPerformance_Add = 73
    Manage_WorkPerformance_Delete = 75
    Manage_WorkPerformance_Edit = 74
    Manage_WorkPerformance_View = 72
    '====================================
    Training = 3
    Training_CompanyTraining = 76
    Training_CompanyTraining_Add = 78
    Training_CompanyTraining_Delete = 80
    Training_CompanyTraining_Edit = 79
    Training_CompanyTraining_View = 77
    Training_CompanyTraining_Detail = 81

    Training_Trainee = 82
    Training_Trainee_Add = 84
    Training_Trainee_Delete = 86
    Training_Trainee_Edit = 85
    Training_Trainee_View = 83
    Training_Trainee_Detail = 87

    Training_Trainee_Experience = 88
    Training_Trainee_Experience_Add = 90
    Training_Trainee_Experience_Delete = 92
    Training_Trainee_Experience_Edit = 91
    Training_Trainee_Experience_View = 89

    Training_Trainee_Education = 93
    Training_Trainee_Education_Add = 95
    Training_Trainee_Education_Delete = 97
    Training_Trainee_Education_Edit = 96
    Training_Trainee_Education_View = 94

    Training_Trainee_Family = 98
    Training_Trainee_Family_Add = 100
    Training_Trainee_Family_Delete = 102
    Training_Trainee_Family_Edit = 101
    Training_Trainee_Family_View = 99

    Training_Skill = 103
    Training_Skill_Add = 105
    Training_Skill_Delete = 107
    Training_Skill_Edit = 106
    Training_Skill_View = 104
    '==============================
    Report = 4
    Security = 3
    Security_Role = 58
    Security_Role_Add = 60
    Security_Role_Delete = 62
    Security_Role_Edit = 61
    Security_Role_View = 59

    Security_User = 53
    Security_User_Add = 55
    Security_User_Delete = 57
    Security_User_Edit = 56
    Security_User_View = 54

    Trans = 37
    Trans_Invoice = 38
    Trans_Invoice_Add = 40
    Trans_Invoice_Delete = 42
    Trans_Invoice_Edit = 41
    Trans_Invoice_View = 39

    Trans_Purchase = 43
    Trans_Purchase_Add = 45
    Trans_Purchase_Delete = 47
    Trans_Purchase_Edit = 46
    Trans_Purchase_View = 44

    Trans_Transfer = 48
    Trans_Transfer_Add = 50
    Trans_Transfer_Delete = 52
    Trans_Transfer_Edit = 51
    Trans_Transfer_View = 49
End Enum
